<template>
  <div class="loginPage">
    <div class="header">
      <div class="logo">
        <img src="../assets/51job_logo2x.png" alt="" @click="$router.push('/')" />
        <img src="../assets/slogan2x.png" alt="" />
      </div>
      <p>客服热线：400-1234-1234</p>
    </div>

    <div class="main">
      <div class="left">
        <div class="block">
          <img src="../assets/login_pic1.png" alt="" />
          <div class="desc">
            <h5>职位优选</h5>
            <p>360行任你挑选</p>
          </div>
        </div>
        <div class="block">
          <img src="../assets/login_pic2.png" alt="" />
          <div class="desc">
            <h5>快速投递</h5>
            <p>分秒必争直达HR</p>
          </div>
        </div>
        <div class="block">
          <img src="../assets/login_pic3.png" alt="" />
          <div class="desc">
            <h5>高效反馈</h5>
            <p>谁看我简历早知道</p>
          </div>
        </div>
      </div>
      <div class="right">
        <router-link class="topRight" to="/register">注册</router-link>
        <div class="main">
          <p class="header">用户登录</p>
          <div class="userInput">
            <span>用户名</span>
            <input v-model="username" type="text" placeholder="请输入用户名" />
          </div>
          <div class="userInput">
            <span>密码</span>
            <input v-model="password" type="password" placeholder="请输入密码" />
          </div>
          <input type="button" class="btn" value="立即登录" @click="login" :class="{ active: btnActive }" />
          <div class="userTerms">
            <label>
              <input type="checkbox" v-model="termsState" />
              我已阅读《用户条款》、《登录条款》
            </label>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
      termsState: false,
    }
  },
  methods: {
    login() {
      const url = '/login'
      const params = `username=${this.username}&password=${this.password}`
      this.axios.post(url, params).then((res) => {
        if (res.data.code == 200) {
          alert('登录成功')
          this.$router.push('/')
        } else if (res.data.code == 201) {
          alert('用户名不存在或密码错误')
        } else {
          alert('登录失败')
        }
      })
    },
  },
  computed: {
    btnActive() {
      return this.username && this.password && this.termsState
    },
  },
}
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}

.loginPage {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #f5f5f5;

  > .header {
    display: flex;
    width: 1200px;
    height: 56px;
    margin: 16px auto;
    justify-content: space-between;

    .logo {
      > img:first-child {
        margin-top: 8px;
        height: 40px;
      }
      > img:first-child:hover {
        cursor: pointer;
      }
      > img:last-child {
        margin: 0 0 10px 10px;
        height: 17px;
      }
    }

    p {
      height: 100%;
      line-height: 56px;
      font-size: 14px;
      color: #bbb;
    }
  }

  > .main {
    display: flex;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 656px;
    height: 398px;
    background-color: #fff;
    border-radius: 14px;
    box-shadow: 0 0 20px 0 #eeeeee;

    .left {
      display: flex;
      flex-direction: column;
      justify-content: center;
      width: 240px;
      height: 100%;
      box-sizing: border-box;

      .block {
        display: flex;
        height: 45px;
        justify-content: space-around;
        margin: 28px 40px;

        img {
          width: 32px;
          height: 32px;
          margin-top: 5px;
          margin-right: 10px;
        }

        h5 {
          margin-bottom: 5px;
          font-weight: normal;
          font-size: 14px;
          line-height: 20px;
          color: #888;
        }

        p {
          font-size: 12px;
          color: #bbb;
        }
      }
    }

    .right {
      width: 416px;
      height: 100%;
      box-shadow: 0 0 20px 0 #eeeeee;

      .topRight {
        position: relative;
        top: 10px;
        left: 340px;
        width: 32px;
        display: block;
        text-decoration: none;
        padding: 10px;
        color: #666;
      }

      .topRight:hover {
        color: #ed6b2c;
      }

      .main {
        padding: 0 48px;

        .header {
          padding: 32px 0 24px;
          color: #333;
          font-size: 20px;
          text-align: center;
          font-weight: bold;
        }

        .userInput {
          display: flex;
          position: relative;
          height: 32px;
          margin-bottom: 20px;

          > span {
            width: 20%;
            height: 32px;
            padding-right: 10px;
            line-height: 32px;
            text-align: justify;
            text-align-last: justify;
          }

          > input {
            width: 80%;
            height: 32px;
            vertical-align: middle;
            box-sizing: border-box;
            padding: 0 10px;
            outline: none;
          }

          > input:focus {
            border: 1px solid #ed6b2c;
          }

          p {
            position: absolute;
            left: 72px;
            top: 32px;
            color: #ed6b2c;
            font-size: 12px;
          }
        }
      }

      .btn {
        width: 100%;
        height: 40px;
        line-height: 40px;
        color: #fff;
        background-color: #888;
        text-align: center;
        border: none;
        border-radius: 5px;
        font-size: 18px;
        margin: 8px 0 12px;
        pointer-events: none;
      }

      .btn.active {
        background-color: #ed6b2c;
        pointer-events: all;
      }

      .btn.active:hover {
        background-color: #d96228;
      }

      .userTerms {
        color: #666;
        font-size: 12px;
        margin-top: 10px;

        input {
          display: inline-block;
          height: 18px;
          margin-right: 5px;
          vertical-align: middle;
        }
      }
    }
  }
}
</style>
